package cookie;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doRequest(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doRequest(request, response);
	}

	public void doRequest(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		Cookie cookie = new Cookie("test", "cookie value");
		Cookie cokkie2 = new Cookie("c2", "2");
		response.addCookie(cookie);
		response.addCookie(cokkie2);
		RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/cookie.jsp");
		dispatcher.forward(request, response);
	}

}
